<?php
$pet_id = $_REQUEST["pet_id"];
?>

<script type="text/javascript">
    $(document).ready(function() {
        //$("#example").dataTable();

    });

    function cancel(return_id, borrow_id, return_amount, pet_id) {
        if (confirm("คุณต้องการยกเลิกรายการนี้ใช่หรือไม่")) {
            var task = "return_borrow_cancel";
            $.post(
                    "return_process.php",
                    {return_id: return_id, borrow_id: borrow_id, return_amount: return_amount, task: task},
            function(data) {
                //alert("success");
                //$("#disp").html(data);
                window.location.href = "index.php?pages=return_borrow_view&pet_id=" + pet_id;
            }
            );
        }

    }
    
    function print(return_id, borrow_id, pet_id) {
        
    }
</script>

<?php
//require_once 'includes/connect.php';
//require_once 'includes/function.php';
//
$db = new myDBS();
$sql = "SELECT * FROM tbl_return "
        . " WHERE pet_id = '$pet_id' "
        . " AND status <> 'cancel'";

$result = $db->runSQL($sql);
?>

<div id="disp"></div>
<div class="container" >
<a href="index.php?pages=return_borrow_edit&pet_id=<?php echo $pet_id; ?>" class="btn primary" id="add_new">ชำระเงิน</a>
<table id="example" class="table table-bordered table-hover" >
    <thead>
    <th>#</th>
    <th>วันที่คืน</th>
    <th>จำนวนที่คืน</th>
    <th>action</th>
</thead>
<tbody>

    <?php
    $i = 1;
    while ($rows = $db->fetch_object($result)) {
        ?>
        <tr>
            <td><p class="text-center"><?php echo $i; ?></p></td>
            <td><p class="text-center"><?php echo $rows->return_date; ?></p></td>
            <td><p class="text-right"><?php echo number_format($rows->return_amount, 2); ?></p></td>
            <td>
                <a href="javascript:cancel('<?php echo $rows->return_id; ?>', '<?php echo $rows->borrow_id; ?>', '<?php echo $rows->return_amount; ?>', '<?php echo $rows->pet_id; ?>')"><i class="icon-remove"></i></a>
                &nbsp;|&nbsp; <a href="print('<?php echo $rows->return_id; ?>', '<?php echo $rows->borrow_id; ?>', '<?php echo $rows->pet_id; ?>')" title="ใบเสร็จ" target="_blank"><i class="icon-print"></i></a>
            </td>
        </tr>
        <?php
        $i++;
    }
    ?>

</tbody>
</table>

</div>

<!--<div class="form-actions">
            
            <input type="hidden" id="id" name="id" value="<?php echo $id; ?>">
            <input type="hidden" id="tblname" name="tblname" value="<?php echo $tblname; ?>">
            <input type="hidden" id="task" name="task" value="cancel">
    

    <button type="submit" class="btn btn-info" id="save_changes" >บันทึกข้อมูล</button>
    <input type="submit" class="btn btn-info" value="บันทึกข้อมูล">
    <a class="btn close-dialog"><i class="icon-remove-sign"></i> ปิด</a>

</div>-->
<!--</form>-->